﻿#include "router.h"

#include <stdexcept>

Router::Router() {}


void Router::registerCallback(const std::string& args, std::function<void(std::shared_ptr<Protocol>, const hv::SocketChannelPtr&)> func) {
    if (routerMap.count(args) != 0) {
        throw std::runtime_error("当前已注册args:" + args + "请检查编码");
    }
    routerMap.emplace(args, func);
}

const std::function<void(std::shared_ptr<Protocol>, const hv::SocketChannelPtr& channel)>& Router::operator[](const std::string& args) {
    return routerMap[args];
}

const std::function<void(std::shared_ptr<Protocol>, const hv::SocketChannelPtr& channel)>& Router::get(const std::string& args) {
    return routerMap[args];
}

